package javabasic.threads.getsubthreadvalue;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableGet {
    public static void main(String[] args) {
        GetSub01 getSub01 = new GetSub01();
        FutureTask<String> stringFutureTask = new FutureTask<String>(getSub01);
        Thread thread = new Thread(stringFutureTask);
        thread.start();
        while (!stringFutureTask.isDone()){
            System.out.println("子线程未执行完，请等待。。。");
        }
        try {
            System.out.println(stringFutureTask.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}

class GetSub01 implements Callable{
    private String str="sub thread value";
    @Override
    public Object call() throws Exception {
        Thread.sleep(100);
        return str;
    }
}
